using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the ActivityLog class.
	/// </summary>
    [Serializable]
	public partial class ActivityLogCollection : ActiveList<ActivityLog, ActivityLogCollection>
	{	   
		public ActivityLogCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>ActivityLogCollection</returns>
		public ActivityLogCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                ActivityLog o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_ActivityLog table.
	/// </summary>
	[Serializable]
	public partial class ActivityLog : ActiveRecord<ActivityLog>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public ActivityLog()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public ActivityLog(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public ActivityLog(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public ActivityLog(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_ActivityLog", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarActivityLogId = new TableSchema.TableColumn(schema);
				colvarActivityLogId.ColumnName = "ActivityLogId";
				colvarActivityLogId.DataType = DbType.Guid;
				colvarActivityLogId.MaxLength = 0;
				colvarActivityLogId.AutoIncrement = false;
				colvarActivityLogId.IsNullable = false;
				colvarActivityLogId.IsPrimaryKey = true;
				colvarActivityLogId.IsForeignKey = false;
				colvarActivityLogId.IsReadOnly = false;
				colvarActivityLogId.DefaultSetting = @"";
				colvarActivityLogId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarActivityLogId);
				
				TableSchema.TableColumn colvarObjectId = new TableSchema.TableColumn(schema);
				colvarObjectId.ColumnName = "ObjectId";
				colvarObjectId.DataType = DbType.Guid;
				colvarObjectId.MaxLength = 0;
				colvarObjectId.AutoIncrement = false;
				colvarObjectId.IsNullable = true;
				colvarObjectId.IsPrimaryKey = false;
				colvarObjectId.IsForeignKey = false;
				colvarObjectId.IsReadOnly = false;
				colvarObjectId.DefaultSetting = @"";
				colvarObjectId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarObjectId);
				
				TableSchema.TableColumn colvarObjectName = new TableSchema.TableColumn(schema);
				colvarObjectName.ColumnName = "ObjectName";
				colvarObjectName.DataType = DbType.String;
				colvarObjectName.MaxLength = 255;
				colvarObjectName.AutoIncrement = false;
				colvarObjectName.IsNullable = true;
				colvarObjectName.IsPrimaryKey = false;
				colvarObjectName.IsForeignKey = false;
				colvarObjectName.IsReadOnly = false;
				colvarObjectName.DefaultSetting = @"";
				colvarObjectName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarObjectName);
				
				TableSchema.TableColumn colvarMessage = new TableSchema.TableColumn(schema);
				colvarMessage.ColumnName = "Message";
				colvarMessage.DataType = DbType.String;
				colvarMessage.MaxLength = 255;
				colvarMessage.AutoIncrement = false;
				colvarMessage.IsNullable = true;
				colvarMessage.IsPrimaryKey = false;
				colvarMessage.IsForeignKey = false;
				colvarMessage.IsReadOnly = false;
				colvarMessage.DefaultSetting = @"";
				colvarMessage.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMessage);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = false;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				colvarCreatedOn.DefaultSetting = @"";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = false;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarType = new TableSchema.TableColumn(schema);
				colvarType.ColumnName = "Type";
				colvarType.DataType = DbType.Int32;
				colvarType.MaxLength = 0;
				colvarType.AutoIncrement = false;
				colvarType.IsNullable = false;
				colvarType.IsPrimaryKey = false;
				colvarType.IsForeignKey = false;
				colvarType.IsReadOnly = false;
				colvarType.DefaultSetting = @"";
				colvarType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarType);
				
				TableSchema.TableColumn colvarIp = new TableSchema.TableColumn(schema);
				colvarIp.ColumnName = "IP";
				colvarIp.DataType = DbType.AnsiString;
				colvarIp.MaxLength = 39;
				colvarIp.AutoIncrement = false;
				colvarIp.IsNullable = true;
				colvarIp.IsPrimaryKey = false;
				colvarIp.IsForeignKey = false;
				colvarIp.IsReadOnly = false;
				colvarIp.DefaultSetting = @"";
				colvarIp.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIp);
				
				TableSchema.TableColumn colvarUserAgent = new TableSchema.TableColumn(schema);
				colvarUserAgent.ColumnName = "UserAgent";
				colvarUserAgent.DataType = DbType.AnsiString;
				colvarUserAgent.MaxLength = 255;
				colvarUserAgent.AutoIncrement = false;
				colvarUserAgent.IsNullable = true;
				colvarUserAgent.IsPrimaryKey = false;
				colvarUserAgent.IsForeignKey = false;
				colvarUserAgent.IsReadOnly = false;
				colvarUserAgent.DefaultSetting = @"";
				colvarUserAgent.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserAgent);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_ActivityLog",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("ActivityLogId")]
		[Bindable(true)]
		public Guid ActivityLogId 
		{
			get { return GetColumnValue<Guid>(Columns.ActivityLogId); }
			set { SetColumnValue(Columns.ActivityLogId, value); }
		}
		  
		[XmlAttribute("ObjectId")]
		[Bindable(true)]
		public Guid? ObjectId 
		{
			get { return GetColumnValue<Guid?>(Columns.ObjectId); }
			set { SetColumnValue(Columns.ObjectId, value); }
		}
		  
		[XmlAttribute("ObjectName")]
		[Bindable(true)]
		public string ObjectName 
		{
			get { return GetColumnValue<string>(Columns.ObjectName); }
			set { SetColumnValue(Columns.ObjectName, value); }
		}
		  
		[XmlAttribute("Message")]
		[Bindable(true)]
		public string Message 
		{
			get { return GetColumnValue<string>(Columns.Message); }
			set { SetColumnValue(Columns.Message, value); }
		}
		  
		[XmlAttribute("CreatedOn")]
		[Bindable(true)]
		public DateTime CreatedOn 
		{
			get { return GetColumnValue<DateTime>(Columns.CreatedOn); }
			set { SetColumnValue(Columns.CreatedOn, value); }
		}
		  
		[XmlAttribute("CreatedBy")]
		[Bindable(true)]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }
			set { SetColumnValue(Columns.CreatedBy, value); }
		}
		  
		[XmlAttribute("Type")]
		[Bindable(true)]
		public int Type 
		{
			get { return GetColumnValue<int>(Columns.Type); }
			set { SetColumnValue(Columns.Type, value); }
		}
		  
		[XmlAttribute("Ip")]
		[Bindable(true)]
		public string Ip 
		{
			get { return GetColumnValue<string>(Columns.Ip); }
			set { SetColumnValue(Columns.Ip, value); }
		}
		  
		[XmlAttribute("UserAgent")]
		[Bindable(true)]
		public string UserAgent 
		{
			get { return GetColumnValue<string>(Columns.UserAgent); }
			set { SetColumnValue(Columns.UserAgent, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varActivityLogId,Guid? varObjectId,string varObjectName,string varMessage,DateTime varCreatedOn,string varCreatedBy,int varType,string varIp,string varUserAgent)
		{
			ActivityLog item = new ActivityLog();
			
			item.ActivityLogId = varActivityLogId;
			
			item.ObjectId = varObjectId;
			
			item.ObjectName = varObjectName;
			
			item.Message = varMessage;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.Type = varType;
			
			item.Ip = varIp;
			
			item.UserAgent = varUserAgent;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varActivityLogId,Guid? varObjectId,string varObjectName,string varMessage,DateTime varCreatedOn,string varCreatedBy,int varType,string varIp,string varUserAgent)
		{
			ActivityLog item = new ActivityLog();
			
				item.ActivityLogId = varActivityLogId;
			
				item.ObjectId = varObjectId;
			
				item.ObjectName = varObjectName;
			
				item.Message = varMessage;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.Type = varType;
			
				item.Ip = varIp;
			
				item.UserAgent = varUserAgent;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ActivityLogIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ObjectIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ObjectNameColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn MessageColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn TypeColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn IpColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn UserAgentColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ActivityLogId = @"ActivityLogId";
			 public static string ObjectId = @"ObjectId";
			 public static string ObjectName = @"ObjectName";
			 public static string Message = @"Message";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CreatedBy = @"CreatedBy";
			 public static string Type = @"Type";
			 public static string Ip = @"IP";
			 public static string UserAgent = @"UserAgent";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
